home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / astero_1 / form1.frm < prev   
Text File  |  1998-01-28  |  9KB  |  318 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   6015
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1560
  7.    ClientWidth     =   7110
  8.    ClipControls    =   0   'False
  9.    ControlBox      =   0   'False
  10.    DrawStyle       =   5  'Transparent
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    PaletteMode     =   1  'UseZOrder
  15.    ScaleHeight     =   6015
  16.    ScaleWidth      =   7110
  17.    WindowState     =   2  'Maximized
  18.    Begin VB.PictureBox Picture1 
  19.       Appearance      =   0  'Flat
  20.       BackColor       =   &H00000000&
  21.       ForeColor       =   &H80000008&
  22.       Height          =   5655
  23.       Left            =   0
  24.       ScaleHeight     =   5625
  25.       ScaleWidth      =   6825
  26.       TabIndex        =   0
  27.       Top             =   0
  28.       Width           =   6855
  29.    End
  30. End
  31. Attribute VB_Name = "Form1"
  32. Attribute VB_GlobalNameSpace = False
  33. Attribute VB_Creatable = False
  34. Attribute VB_PredeclaredId = True
  35. Attribute VB_Exposed = False
  36. Dim cx As Double
  37. Dim cy As Double
  38. Dim OldCX As Double
  39. Dim OldCY As Double
  40. Dim X() As Double
  41. Dim Y() As Double
  42. Dim BulletsLoose As Integer
  43. Dim da As Double
  44. Dim db As Double
  45. Dim Direction As Double
  46. Dim Speed As Integer
  47. Dim Pie As Double
  48. Dim Forward As Boolean
  49. Dim TurnLeft As Boolean
  50. Dim TurnRight As Boolean
  51. Dim Firing As Boolean
  52. Dim ReallyFiring As Boolean
  53. Dim RefreshWin As Boolean
  54. Dim Radians As Double
  55. Dim Shields As Boolean
  56. Dim Projectile(100) As BulletData
  57. Dim BaseStart As Double
  58. Dim BaseEnd As Double
  59. Private Type BulletData
  60.     Active As Boolean
  61.     DistanceMoved As Integer
  62.     BulletX As Double
  63.     BulletY As Double
  64.     BulletDirection As Double
  65. End Type
  66. Private Declare Function GetActiveWindow Lib "User32" () As Integer
  67. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'Halt the system for specified Time
  68.  
  69. Sub DrawShip()
  70. Picture1.ForeColor = RGB(255, 255, 255)
  71. X(1) = (cx + (Sin(Direction)) * 300)
  72. Y(1) = (cy + (Cos(Direction)) * 300)
  73. X(2) = (cx + (Sin(Direction + Degrees(140))) * 300)
  74. Y(2) = (cy + (Cos(Direction + Degrees(140))) * 300)
  75. X(3) = (cx + (Sin(Direction + Degrees(220))) * 300)
  76. Y(3) = (cy + (Cos(Direction + Degrees(220))) * 300)
  77. 'Thrusters
  78. X(4) = (cx + (Sin(Direction + Degrees(210))) * 320)
  79. Y(4) = (cy + (Cos(Direction + Degrees(210))) * 320)
  80. X(5) = (cx + (Sin(Direction + Degrees(150))) * 320)
  81. Y(5) = (cy + (Cos(Direction + Degrees(150))) * 320)
  82.  
  83. X(6) = (cx + (Sin(Direction + Degrees(200))) * 330)
  84. Y(6) = (cy + (Cos(Direction + Degrees(200))) * 330)
  85. X(7) = (cx + (Sin(Direction + Degrees(160))) * 330)
  86. Y(7) = (cy + (Cos(Direction + Degrees(160))) * 330)
  87.  
  88. X(8) = (cx + (Sin(Direction + Degrees(190))) * 340)
  89. Y(8) = (cy + (Cos(Direction + Degrees(190))) * 340)
  90. X(9) = (cx + (Sin(Direction + Degrees(170))) * 340)
  91. Y(9) = (cy + (Cos(Direction + Degrees(170))) * 340)
  92.  
  93. X(10) = (cx + (Sin(Direction + Degrees(179))) * 350)
  94. Y(10) = (cy + (Cos(Direction + Degrees(179))) * 350)
  95. X(11) = (cx + (Sin(Direction + Degrees(181))) * 350)
  96. Y(11) = (cy + (Cos(Direction + Degrees(181))) * 350)
  97. X(12) = X(2)
  98. Y(12) = Y(2)
  99. X(13) = (cx + (Sin(Direction + Degrees(40))) * 230)
  100. Y(13) = (cy + (Cos(Direction + Degrees(40))) * 230)
  101. X(14) = (cx + (Sin(Direction + Degrees(120))) * 160)
  102. Y(14) = (cy + (Cos(Direction + Degrees(120))) * 160)
  103. X(15) = X(3)
  104. Y(15) = Y(3)
  105. X(16) = (cx + (Sin(Direction + Degrees(320))) * 230)
  106. Y(16) = (cy + (Cos(Direction + Degrees(320))) * 230)
  107. X(17) = (cx + (Sin(Direction + Degrees(240))) * 160)
  108. Y(17) = (cy + (Cos(Direction + Degrees(240))) * 160)
  109.  
  110.  
  111. 'Sheilds
  112.  
  113. If Shields = True Then Picture1.Circle (cx, cy), 400
  114.  
  115. Picture1.Line (X(1), Y(1))-(X(14), Y(14))
  116. Picture1.Line (X(17), Y(17))-(X(1), Y(1))
  117.  
  118. If 360 - UnDegrees(Direction) > 50 Then
  119.     BaseStart = Direction + Degrees(50)
  120. Else
  121.     BaseStart = Direction + Degrees(50) - Degrees(360)
  122. End If
  123.  
  124. If 360 - UnDegrees(Direction) > 130 Then
  125.     BaseEnd = Direction + Degrees(130)
  126. Else
  127.     BaseEnd = Direction + Degrees(130) - Degrees(360)
  128. End If
  129.  
  130. Picture1.Circle (cx, cy), 300, , BaseStart, BaseEnd
  131.  
  132. Picture1.Line (X(12), Y(12))-(X(13), Y(13))
  133. Picture1.Line (X(13), Y(13))-(X(14), Y(14))
  134. Picture1.Line (X(15), Y(15))-(X(16), Y(16))
  135. Picture1.Line (X(16), Y(16))-(X(17), Y(17))
  136.  
  137. If Forward = True Then
  138.     Picture1.Line (X(4), Y(4))-(X(5), Y(5))
  139.     Picture1.Line (X(6), Y(6))-(X(7), Y(7))
  140.     Picture1.Line (X(8), Y(8))-(X(9), Y(9))
  141.     Picture1.Line (X(10), Y(10))-(X(11), Y(11))
  142.  
  143. End If
  144.  
  145. OldCX = cx
  146. OldCY = cy
  147. End Sub
  148. Sub ClearShip()
  149. Picture1.ForeColor = RGB(0, 0, 0)
  150.  
  151. Picture1.Line (X(1), Y(1))-(X(14), Y(14))
  152. Picture1.Line (X(17), Y(17))-(X(1), Y(1))
  153. Picture1.Line (X(4), Y(4))-(X(5), Y(5))
  154. Picture1.Line (X(6), Y(6))-(X(7), Y(7))
  155. Picture1.Line (X(8), Y(8))-(X(9), Y(9))
  156. Picture1.Line (X(10), Y(10))-(X(11), Y(11))
  157. Picture1.Line (X(12), Y(12))-(X(13), Y(13))
  158. Picture1.Line (X(13), Y(13))-(X(14), Y(14))
  159. Picture1.Line (X(15), Y(15))-(X(16), Y(16))
  160. Picture1.Line (X(16), Y(16))-(X(17), Y(17))
  161. Picture1.Circle (OldCX, OldCY), 300, , BaseStart, BaseEnd
  162. Picture1.Circle (OldCX, OldCY), 400
  163. End Sub
  164.  
  165. Private Sub Form_Load()
  166. Startup = True
  167. Pie = 3.14159265358979
  168. Radians = (2 * Pie) / 360
  169. Direction = Degrees(180)
  170. Speed = 1
  171. ReDim X(20)
  172. ReDim Y(20)
  173. ReallyFiring = True
  174. End Sub
  175.  
  176. Private Sub Form_Resize()
  177. Picture1.Width = Form1.Width
  178. Picture1.Height = Form1.Height
  179. cx = Picture1.Width / 2
  180. cy = Picture1.Height / 2
  181. Do Until 1 = 2
  182. If GetActiveWindow <> Form1.hWnd Then
  183. RefreshWin = True
  184. End If
  185. If RefreshWin = True Then
  186.     If GetActiveWindow = Form1.hWnd Then
  187.         RefreshWin = False
  188.         DoEvents
  189.         Picture1.Refresh
  190.         Picture1.SetFocus
  191.         DoEvents
  192.     End If
  193. End If
  194. cx = cx + da
  195. cy = cy + db
  196. CheckWrap
  197. ClearShip
  198. DrawShip
  199. If TurnLeft = True Then
  200. Direction = Direction + Degrees(5)
  201. End If
  202. If TurnRight = True Then
  203. Direction = Direction - Degrees(5)
  204. End If
  205.  
  206. If Direction = Degrees(360) Then Direction = Degrees(0)
  207. If Direction < Degrees(0) Then Direction = Degrees(355)
  208.  
  209. If Forward = True Then
  210. da = da + ((Sin(Direction)) * Speed)
  211. db = db + ((Cos(Direction)) * Speed)
  212. End If
  213. If Firing = True And ReallyFiring = True And Shields = False Then
  214. Dim TempBullet As Integer
  215. 'First Bullet
  216. TempBullet = FindFreeBullet
  217. BulletsLoose = BulletsLoose + 1
  218. Projectile(TempBullet).BulletX = X(13)
  219. Projectile(TempBullet).BulletY = Y(13)
  220. Projectile(TempBullet).Active = True
  221. Projectile(TempBullet).BulletDirection = Direction
  222. 'Second Bullet
  223. TempBullet = FindFreeBullet
  224. BulletsLoose = BulletsLoose + 1
  225. Projectile(TempBullet).BulletX = X(16)
  226. Projectile(TempBullet).BulletY = Y(16)
  227. Projectile(TempBullet).Active = True
  228. Projectile(TempBullet).BulletDirection = Direction
  229.  
  230. ReallyFiring = False
  231. End If
  232. If BulletsLoose > 0 Then UpdateBullets
  233. DoEvents
  234. Sleep (10)
  235. Loop
  236. End Sub
  237.  
  238. Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
  239. If KeyCode = vbKeyLeft Then
  240. TurnLeft = True
  241. ElseIf KeyCode = vbKeyRight Then
  242. TurnRight = True
  243. ElseIf KeyCode = vbKeyUp Then
  244. Forward = True
  245. ElseIf KeyCode = vbKeySpace Then
  246. Firing = True
  247. ElseIf KeyCode = vbKeyDown Then
  248. Shields = True
  249. End If
  250. End Sub
  251.  
  252.  
  253. Private Sub Picture1_KeyUp(KeyCode As Integer, Shift As Integer)
  254. If KeyCode = vbKeyLeft Then
  255. TurnLeft = False
  256. ElseIf KeyCode = vbKeyRight Then
  257. TurnRight = False
  258. ElseIf KeyCode = vbKeyUp Then
  259. Forward = False
  260. ElseIf KeyCode = vbKeySpace Then
  261. ReallyFiring = True
  262. Firing = False
  263. ElseIf KeyCode = vbKeyDown Then
  264. Shields = False
  265. End If
  266. End Sub
  267.  
  268. Sub CheckWrap()
  269. If cy > Picture1.Height Then
  270. cy = 0
  271. End If
  272. If cy < 0 Then
  273. cy = Picture1.Height
  274. End If
  275. If cx > Picture1.Width Then
  276. cx = 0
  277. End If
  278. If cx < 0 Then
  279. cx = Picture1.Width
  280. End If
  281. End Sub
  282. Function Degrees(Number As Double) As Double
  283. Degrees = (Number * Radians)
  284. End Function
  285. Function UnDegrees(Number As Double) As Double
  286. UnDegrees = (Number / Radians)
  287. End Function
  288.  
  289. Sub UpdateBullets()
  290. Dim i As Integer
  291. For i = 1 To UBound(Projectile)
  292. If Projectile(i).Active = True Then
  293. If Projectile(i).BulletX > Picture1.Width Or Projectile